package com.example.getaudit.common.result;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.example.getaudit.common.exception.BusinessExceptionAssert;

/**
 * ClassName CouponResultCode
 * 优惠券模块响应码
 *
 * @author WuTianyu
 * @version 1.0
 * @since 2023/5/17 9:17
 */
public enum CouponResultCode implements BusinessExceptionAssert {

    COUPON_NOT_EXIST(10001, "优惠券不存在"),
    ;

    CouponResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 响应信息w
     */
    private String msg;
    /**
     * 响应信息补充
     */
    private Object[] msgParams;


    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public CouponResultCode setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        if (ArrayUtil.isNotEmpty(msgParams)) {
            return StrUtil.format(msg, msgParams);
        }
        return msg;
    }

    public CouponResultCode setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    @Override
    public IResultEnum setMsgParams(Object... msgParams) {
        this.msgParams = msgParams;
        return this;
    }

    @Override
    public Object[] getMsgParams() {
        return msgParams;
    }
}
